home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 8 / Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO / 034a / aecur101.arj / CONTRIB / CURSES / SRC / BOX.C < prev    next >
C/C++ Source or Header  |  1990-03-08  |  3KB  |  134 lines

  1. /*------------------------------------------------------------
  2.  * 
  3.  *  box.c
  4.  * 
  5.  *  copyright (c) 1987,88,89,90 J. Alan Eldridge
  6.  *  
  7.  *  box a window -- curses 3.X
  8.  * 
  9.  *----------------------------------------------------------*/
  10.  
  11. #include "curses.h"
  12.  
  13. box(win, v, h)
  14. WINDOW  *win;
  15. int     v, h;
  16. {
  17.     /*
  18.         if v and h are 0 or 1, they are interpreted to mean
  19.         the IBM char set line drawing character with single
  20.         or double lines, respectively
  21.         
  22.         if the above case holds, or v and h are really IBM
  23.         line drawing characters, then the corner characters
  24.         are picked from the IBM char set to match
  25.         
  26.         otherwise, v and h are treated as ASCII values, and
  27.         the corners are filled in using the v character
  28.     */
  29.  
  30.     static UCHAR ulchars[2][2] = {
  31.         218, 213,
  32.         214, 201
  33.       };
  34.  
  35.     static UCHAR urchars[2][2] = {
  36.         191, 184,
  37.         183, 187
  38.     };
  39.  
  40.     static UCHAR llchars[2][2] = {
  41.         192, 212,
  42.         211, 200
  43.     };
  44.  
  45.     static UCHAR lrchars[2][2] = {
  46.         217, 190,
  47.         189, 188
  48.     };
  49.  
  50.     static UCHAR hchars[2] = {
  51.         196, 205
  52.     };
  53.  
  54.     static UCHAR vchars[2] = {
  55.         179, 186
  56.     };
  57.  
  58.     int     vtype, 
  59.             htype, 
  60.             cnt, 
  61.             attrib,
  62.             ulchr,
  63.             urchr,
  64.             llchr,
  65.             lrchr;
  66.  
  67.     VIDCHR  *buf;
  68.  
  69.     if (v == 0 || v == 1)
  70.         v = vchars[vtype = v];
  71.     else 
  72.         for (vtype = 1; vtype > -1; vtype--)
  73.             if (v == vchars[vtype])
  74.                 break;
  75.  
  76.     if (h == 0 || h == 1)
  77.         h = hchars[htype = h];
  78.     else 
  79.         for (htype = 1; htype > -1; htype--)
  80.             if (h == hchars[htype])
  81.                 break;
  82.  
  83.     buf = win->buf[0];
  84.     attrib = win->attrib;
  85.  
  86.     if (htype > -1 && vtype > -1) {
  87.         /* IBM box chars */
  88.         ulchr = ulchars[vtype][htype];
  89.         urchr = urchars[vtype][htype];
  90.         llchr = llchars[vtype][htype];
  91.         lrchr = lrchars[vtype][htype];
  92.     } else 
  93.         ulchr = urchr = llchr = lrchr = v;
  94.     
  95.     buf->chr = ulchr;
  96.     buf++->att = attrib;
  97.  
  98.     for (cnt = 1; cnt < win->maxx; cnt++) {
  99.       buf->chr = h;
  100.       buf++->att = attrib;
  101.     }
  102.  
  103.     buf->chr = urchr;
  104.     buf++->att = attrib;
  105.  
  106.     for (cnt = 1; cnt < win->maxy; cnt++) {
  107.         buf = win->buf[cnt];
  108.         buf->chr = v;
  109.         buf->att = attrib;
  110.         buf += win->maxx;
  111.         buf->chr = v;
  112.         buf->att = attrib;
  113.     }
  114.  
  115.     buf = win->buf[cnt];
  116.  
  117.     buf->chr = llchr;
  118.     buf++->att = attrib;
  119.  
  120.     for (cnt = 1; cnt < win->maxx; cnt++) {
  121.         buf->chr = h;
  122.         buf++->att = attrib;
  123.     }
  124.  
  125.     buf->chr = lrchr;
  126.     buf->att = attrib;
  127.  
  128.     touchwin(win);
  129.     win->flags |= _WBOX;
  130.  
  131.     return OK;
  132. }
  133.  
  134.